<?php
 ////////////////////////////
$idkey=$_SESSION['email'];
$result_thanhvien=mysql_query("SELECT * FROM khachhang where email='$idkey'");
$row=mysql_fetch_array($result_thanhvien);
$db_user=$row["tenkh"]; 
$email=$row["email"];
?>
<?php
$bt=isset($_REQUEST["submit"])?$_REQUEST["submit"]:"";
if($bt!=""){	
	$email=$_POST["email"];
	$sql="SELECT * FROM khachhang where email='$email'";
	$result_thanhvien2=mysql_query($sql);
	$row2=mysql_fetch_array($result_thanhvien2);
	$db_matkhau=$row2["pass"]; 	  
	$pw=md5($_POST['pw']);
	$pw1=md5($_POST['cpw']);
	$pw_old=md5($_POST['pw_old']);	
		if ($pw_old==$db_matkhau and $pw==$pw1)
		{	
			$result_changepw = mysql_query("UPDATE khachhang SET pass='$pw' WHERE email='$email'");
			echo "<script>alert('Đổi mật khẩu thành công.'); window.location='index.php';</script>";
		}
		else echo "<script>alert('Đổi mật khẩu thất bại! Kiểm tra lại mật khẩu cũ'); window.history.go(-1);</script>";
}
?>
<form method="post" action="index.php" id="ddd">
<input type="hidden" name="action" value="changepw" />
<table border="0" width="700" cellpadding="0" cellspacing="0" style="border:1px solid #CCCCCC; margin:0 auto 0 20px;">
<tr class="tieude" height="35">
<td colspan="2" align="center">ĐỔI MẬT KHẨU</td>
</tr>
 <tr height="30" bgcolor="#F9F9F9" onmouseover="style.background='#c8dbf0'" onmouseout="style.background='#F9F9F9'">
      <td style="padding-left:100px" align="left">Tên đăng nhập:</td>
      <td width="450px" align="left"><?php echo $db_user; ?>
      <input type="hidden" name="email" value="<?php echo $email;?>" />
      </td>
    </tr>
	<tr height="30" bgcolor="#F9F9F9" onmouseover="style.background='#c8dbf0'" onmouseout="style.background='#F9F9F9'">
      <td style="padding-left:100px">Mật khẩu cũ: </td>
      <td><input name="pw_old" type="password" id="pw_old" style="width:220px" class="required" minlength=6 maxlength=16 /></td>
    </tr>
	<tr height="30" bgcolor="#F9F9F9" onmouseover="style.background='#c8dbf0'" onmouseout="style.background='#F9F9F9'">
      <td style="padding-left:100px">Mật khẩu mới:</td>
      <td><input name="pw" type="password" id="pw" style="width:220px" class="required" minlength=6 maxlength=16 /></td>
    </tr>
	<tr height="30" bgcolor="#F9F9F9" onmouseover="style.background='#c8dbf0'" onmouseout="style.background='#F9F9F9'">
      <td style="padding-left:100px">Viết lại mật khẩu:</td>
      <td><input name="cpw" type="password" id="cpw" style="width:220px" class="required" minlength=6 maxlength=16 /></td>
    </tr>
    <tr>
      <td height="35" colspan="2" bgcolor="#2d94ff">
        <input type="submit" value="Đồng ý" name="submit"  style="height:30px; width:70px; margin-left:210px;">
	<input type="reset" value="Nhập lại"  style="height:30px; width:70px;">
       </td>
    </tr>
  </table>
</form>

